#pragma once

#include <iostream>
#include <functional>
#include <cstdio>

class SaveTask
{
public:
    SaveTask(){}
    SaveTask(std::string message):message_(message){}
    std::string get_message()
    {
        return message_;
    }
private:
    std::string message_;
};

class CalTask
{
private:
    using func_t = std::function<int(int, int, char)>;
public:
    CalTask(){}
    CalTask(int x, int y, func_t func, char opt):x_(x), y_(y), func_(func), opt_(opt) {}
    std::string operator ()()
    {
        int ret = func_(x_, y_, opt_);
        char buffer[1024];
        snprintf(buffer, sizeof buffer, "%d %c %d = %d", x_, opt_, y_, ret);
        return buffer;
    } 
    std::string toTaskString()
    {
        char buffer[1024];
        snprintf(buffer, sizeof buffer, "%d %c %d = ?", x_, opt_, y_);
        return buffer;
    }
private:
    func_t func_;
    int x_;
    int y_;
    char opt_;
};

std::string math = "+-*/%";

int mycal(int x, int y, char opt)
{
    int result;
    switch(opt)
    {
    case '+':
        result = x+y;
        break;
    case '-':
        result = x-y;
        break;
    case '*':
        result = x*y;
        break;
    case '/':
    {
        if(!y)
        {
            std::cerr << "div zero!" << std::endl;
            result = -1;
        }        
        else 
        result = x/y;
    }
        break;
    case '%':
    {
        if(!y)
        {
            std::cerr << "mod zero!" << std::endl;
            result = -1;
        }        
        else 
        result = x%y;
    }
        break;
    default:
        break;
    }
    return result;
}